package org.design.adapterPattern;

/**
 * AudioPlayer
 *
 * @author 樊温军
 * @date 2025/6/17 上午8:54
 */
public class AudioPlayer implements MediaPlayer {
    MediaAdapter mediaAdapter;

    @Override
    public void play(String fileName) {

        //播放 mp3 音乐文件的内置支持
        if (fileName.endsWith(".mp3")) {
            System.out.println("Playing mp3 file. Name: " + fileName);
        }
        //mediaAdapter 提供了播放其他文件格式的支持
        else if (fileName.endsWith(".vlc")
                || fileName.endsWith(".mp4")) {
            mediaAdapter = new MediaAdapter(fileName);
            mediaAdapter.play(fileName);
        } else {
            System.out.println("Invalid media. " +
                    fileName + " format not supported");
        }
    }
}
